﻿Imports QueComer

Public Class LoginForm

    Private Sub UsernameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameLabel.Click

    End Sub

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim negocio As New Login
        Dim us = Me.UsernameTextBox.Text
        Dim pw = Me.PasswordTextBox.Text

        Try
            Dim modelo = negocio.validar(us, pw)

            Dim mdi As PrincipalMDI = New PrincipalMDI

            mdi.UsuariosToolStripMenuItem.Visible = False
            mdi.RestaurantesToolStripMenuItem.Visible = False
            mdi.MiRestauranteToolStripMenuItem.Visible = False
            mdi.RestaurantesToolStripMenuItem.Visible = False
            mdi.BuscadorToolStripMenuItem.Visible = False

            Dim rolex = modelo.rol

            'Si es ADMIN

            If Constantes.ADMIN = rolex Then

                mdi.UsuariosToolStripMenuItem.Visible = True
                mdi.RestaurantesToolStripMenuItem.Visible = True

                'Si es ADM_REST

            ElseIf Constantes.ADM_REST = rolex Then

                Dim rest = modelo.restaurante

                mdi.MiRestauranteToolStripMenuItem.Visible = True
                mdi.BuscadorToolStripMenuItem.Visible = True

                mdi.MiRestauranteToolStripMenuItem.Text = rest

                'Si es USER

            Else

                mdi.BuscadorToolStripMenuItem.Visible = True

            End If

            mdi.Show()
            Me.Visible = False

        Catch ex As Exception
            Me.lblError.Text = "Usuario y/o Clave incorrectos"
        End Try
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Close()
    End Sub

    Private Sub LoginForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub PasswordTextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles PasswordTextBox.TextChanged
        If PasswordTextBox.Text = "" Then
            OK.Enabled = False
        Else
            OK.Enabled = True
        End If

        If UsernameTextBox.Text = "" Then
            OK.Enabled = False
        Else
            OK.Enabled = True
        End If

    End Sub

    Private Sub UsernameTextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles UsernameTextBox.TextChanged
        If UsernameTextBox.Text = "" Then
            OK.Enabled = False
        Else
            OK.Enabled = True
        End If

        If PasswordTextBox.Text = "" Then
            OK.Enabled = False
        Else
            OK.Enabled = True
        End If

    End Sub
End Class